package com.Test;

public class Change10To2 {
    public static void main(String[] args) {
        int n = 22;
        //   Integer.toBinaryString() 将整数转成其对应的二进制字符串
        String str = Integer.toBinaryString(n);
        System.out.println(str);//10110

        int len = str.length();
        int lastindx = len, max = 0;
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) == '1') {
                max = Math.max(max, i - lastindx);
                lastindx = i;
            }
        }

        System.out.println(max);
    }
}
